
import axios from '@/utils/request'
export default {
  Video: {
    entity: { name: 'Content', prefix: `manage` },
    form: {
      fields: [
        'title',
        {
          property: 'category',
          field_options: { label: '类型' },
          relation_filter: {
            '@filter': 'entity.getType().getSlug() == "video" && entity.getParent()'
          }
        },
        {
          property: 'cover',
          field_options: { label: '视频链接' },
          help: '请上传可以直接访问的视频链接'
        },
        {
          property: 'video',
          field_options: { label: '视频封面' },
          type: 'image'
        },
        'listOrder',
        'content'
      ]
    },
    list: {
      actions: [
        {
          name: '批量上下架',
          position: 'top',
          component:
            () => import('@/views/video/batch.vue')
        }
      ],
      query: {
        '@filter': 'entity.getCategory().getType().getSlug() == "video"',
        '@order': 'entity.id|DESC'
      },
      list_filter: {
        'title': '标题',
        'category.id': () => {
          return axios
            .get('/api/categories',
              { params: { '@filter':  'entity.getType().getSlug() == "video" && entity.getParent()' } })
            .then(res =>
              Object.assign(
                { __label: '产品分类' },
                ...res.data.map(v => { return { [v.id]: `${v.name}(${v.parent.__toString})` } })
              )
            )
        }
      },
      list_display: [
        'title',
        // { property: 'cover', type: 'image' },
        // 'category',
        {
          property: 'enabled',
          editable: true
        },
        // 'title',
        // 'createdTime'
        {
          property: 'video',
          label: '封面',
          editable: true
        },
        {
          property: 'listOrder',
          label: '顺序',
          editable: true
        },
      ]
    }
  }
}
